using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;

[CreateAssetMenu()]
public class GameSO : ScriptableObject
{
    public MapSO[] mapArray;
    public int selectedMapID = -1;
    public int selectedLevelID = -1;

    public void UpdateLevel(int number)
    {
        if (number <= 0)
        {
            return;
        }

        if (number > mapArray[selectedMapID - 1].numberOfLevel[selectedLevelID - 1])
        {
            mapArray[selectedMapID - 1].starNumberOfMap +=
                (number - mapArray[selectedMapID - 1].numberOfLevel[selectedLevelID - 1]); //更新总数
            mapArray[selectedMapID - 1].numberOfLevel[selectedLevelID - 1] = number; //更新关卡星星数
        }

        if (selectedLevelID >= mapArray[selectedMapID - 1].numberOfLevel.Length) //到达最后一个关卡
        {
            if (selectedMapID < mapArray.Length && mapArray[selectedMapID].starNumberOfMap == -1) //下一张地图存在并处于未解锁状态
            {
                mapArray[selectedMapID].starNumberOfMap = 0; //解锁下一张地图
                mapArray[selectedMapID].numberOfLevel[0] = 0; //解锁下一张地图的第一个关卡
            }
        }
        else
        {
            //判断下一个是否开启
            if (mapArray[selectedMapID - 1].numberOfLevel[selectedLevelID] == -1)
            {
                mapArray[selectedMapID - 1].numberOfLevel[selectedLevelID] = 0;
            }
        }
    }
}